package ctrlMode

import (
	"emsctrl/policy"
	"emsctrl/public"
	"emsctrl/servicedevmap"
	"fmt"
	"time"
)

// 自动
type AutoPolicy struct {
	CuPolicy   *public.CurrentPolicy
	AutoPolicy public.Policy_Inter
}

func (a *AutoPolicy) PvActivePowerSet(f float32) {
	//TODO implement me
	fmt.Println("Pv active power:", f)
	servicedevmap.PvActionPower(f)
}

func (a *AutoPolicy) PcsOpenSet() {
	//TODO implement me
	fmt.Println("Pcs open set me")
	servicedevmap.PcsOpen(1)
}

func (a *AutoPolicy) PcsCloseSet() {
	//TODO implement me
	fmt.Println(time.Now().Unix(), "pcs close set me")
	servicedevmap.PcsClose(1)
}

func (a *AutoPolicy) PcsRemoteSet() {
	fmt.Println(time.Now().Unix(), "pcs remote set me")
	servicedevmap.PcsRemote(1)
}

func (a *AutoPolicy) BmsUpHighVolSet(onoff int) {
	//TODO implement me
	fmt.Println("implement me")
}

func (a *AutoPolicy) BmsDownHighVolSet(onoff int) {
	//TODO implement me
	fmt.Println("implement me")
}

func (a *AutoPolicy) AirCondOpenSet(onoff int) {
	//TODO implement me
	fmt.Println("implement me")
}

func (a *AutoPolicy) PcsActivePowerSet(power float32) {
	//TODO implement me
	fmt.Println("Active Power:", power)
	servicedevmap.PcsActionPower(power)

}

func (a *AutoPolicy) PcsReactivePowerSet(power float32) {
	//TODO implement me
	fmt.Println("Reactive power:", power)
}

func (a *AutoPolicy) PcsOpenCheck() {
	//TODO implement me
	fmt.Println("implement me pcs state:", a.CuPolicy.RemoteSignal.PcsOpenState)

}

func (a *AutoPolicy) PcsCloseCheck() {
	//TODO implement me
	fmt.Println("implement me pcs state:", a.CuPolicy.RemoteSignal.PcsOpenState)
}

func (a *AutoPolicy) BmsUpHighVolCheck() {
	//TODO implement me
	fmt.Println("implement me")
}

func (a *AutoPolicy) BmsDownHighVolCheck() {
	//TODO implement me
	fmt.Println("implement me")
}

func (a *AutoPolicy) AirCondOpenCheck() {
	//TODO implement me
	fmt.Println("implement me")
}

func (a *AutoPolicy) PcsActivePowerCheck() {
	//TODO implement me
	fmt.Println("implement me")
}

func (a *AutoPolicy) PcsReactivePowerCheck() {
	//TODO implement me
	fmt.Println("implement me")
}

func (a *AutoPolicy) PolicySet(currentPolicy *public.CurrentPolicy) {
	//TODO implement me
	a.CuPolicy = currentPolicy
	switch a.CuPolicy.RemoteAdjRemoteCtrMng.RemoteAdj.PolicyMode {
	case public.NO_POLICY:
		a.AutoPolicy = &policy.No_policy{}
	case public.PEEK_LOAD_SHIFT:
		a.AutoPolicy = &policy.Peak_load_shift{}
	case public.INCREASE_CAPACITY:
		a.AutoPolicy = &policy.Increase_capacity{}
	case public.BAT_STORA_PV_UNCTRL:
		a.AutoPolicy = &policy.Bar_stora_pv_unctrl{}
	case public.BAT_STORA_PV_CTRL:
		a.AutoPolicy = &policy.Bat_stora_pv_ctrl{}
	case public.BAT_STORA_GENEATOR:
		a.AutoPolicy = &policy.Bat_stora_generator{}
	case public.BAT_PV_CTRL_ONOFF_GRID:
		a.AutoPolicy = &policy.Bat_pv_ctrl_onoff_grid{}
	case public.BAT_PV_CTRL_GENERATOR_ONOFF_GRID:
		a.AutoPolicy = &policy.Bat_pv_ctrl_generator_onoff_grid{}
	case public.BAT_STORA_EV:
		a.AutoPolicy = &policy.Bar_stora_ev{}
	case public.BAT_STORA_PV_EV:
		a.AutoPolicy = &policy.Bar_stora_pv_ev{}
	}
	a.AutoPolicy.ParaSet(currentPolicy)
	fmt.Println("Policy set me")
}

func (a *AutoPolicy) Implement() bool {
	//TODO implement me
	run := a.AutoPolicy.Run()
	if run == true {
		return true
	}
	fmt.Println("auto policy me")
	return false

}
